package cn.qdhlm.collectservice.core.handler;

import cn.qdhlm.collectservice.core.component.Commander;
import cn.qdhlm.collectservice.model.dto.CommandParamDTO;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Name:CommandHandler
 * @description:
 * @author: xinY
 **/
@Component
public class CommandHandler {
    @Autowired
    private Commander commander;
    public String process(MessageExt msg){
        CommandParamDTO commandParamDTO = JSONObject.parseObject(msg.getBody(),CommandParamDTO.class);
        try {
            return commander.execute(commandParamDTO.getAfn(),commandParamDTO.getFn(),commandParamDTO);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
